#define _CRT_SECURE_NO_WARNING 1
#include<stdio.h> 
#define MAX 100
int main(){
	int i = 0;
	int  j = 0;
	int a[MAX][MAX] = { 0 };
	int n = 0;
	int  k = 1;
	printf("please input a number n:");
	while (scanf("%d", &n) != EOF)
	{
		k = 1;
		for (i = 1; i <= n / 2; ++i)
		{
			for (j = i; j <= n - i; ++j) /* 左侧 */
				a[i][j] = k++;

			for (j = i; j <= n - i; ++j) /* 下方 */
				a[j][n + 1 - i] = k++;

			for (j = n - i + 1; j >= i + 1; j = j - 1) /* 右侧 */
				a[n + 1 - i][j] = k++;

			for (j = n - i + 1; j >= i + 1; j = j - 1) /* 上方 */
				a[j][i] = k++;
		}
		if (n != 1){
			for (i = 1; i <= n; ++i){
				for (j = 1; j <= n; ++j)
					printf("%5d", a[i][j]); printf("\n");
			}
		}
		else
			printf("%5d\n", n);
		printf("please input a number n:");
	}
	return 0;
}